#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    struct Reustaurant
    {
        int id, rating;
        bool operator<(const Reustaurant &r) const
        {
            return rating == r.rating ? id > r.id : rating > r.rating;
        }
    };
    vector<int> filterRestaurants(vector<vector<int>> &restaurants, int veganFriendly, int maxPrice, int maxDistance)
    {
        vector<Reustaurant> tmp;
        for (auto &r : restaurants)
        {
            if (r[2] >= veganFriendly && r[3] <= maxPrice && r[4] <= maxDistance)
            {
                tmp.push_back({r[0], r[1]});
            }
        }
        sort(tmp.begin(), tmp.end());
        vector<int> ans;
        for (auto &r : tmp)
        {
            ans.push_back(r.id);
        }
        return ans;
    }
};